//
//  TestAutoCell.swift
//  CooperSwift_Example
//
//  Created by 计海峰 on 2021/5/19.
//  Copyright © 2021 CocoaPods. All rights reserved.
//

import UIKit
import CooperSwift


//extension UITableViewCell : BindToProtocol {
//
//    @objc func bindTo(_ info: Any?) {
//        guard let info = info else { return }
//        self.info = info
//    }
//
//}


class TestAutoCell: UITableViewCell {

    @IBOutlet weak var titleLB: UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    @IBAction func btnTap(_ sender: Any) {
        guard let info = self.info as? TestClasCellModel else { return }
        info.post("sumbit")
        info.postTableService(.reloadCell)
    }
    
     @objc override func bindTo(_ info: Any?) {
        super.bindTo(info)
        if let info = info as? TestClasCellModel {
            titleLB.text = (info.model as! String)
            return
        }
        guard let model = info as? TestCellModel else { return }
        titleLB.text = (model.model as! String)
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}

class TestClasCellModel: NSObject, TableCellConfigProtocol, BindKeyProtocol {
  
    
    var model: Any?
    
    required init(_ model: Any?) {
        self.model = model
    }
    
    func cellCls() -> UITableViewCell.Type {
        return TestAutoCell.self
    }
    
}
